home *** CD-ROM | disk | FTP | other *** search
- Path: news.lpr.carel.fi!usenet
- From: Ari Lukumies <aril@cmt.lpr.mail.carel.fi>
- Newsgroups: comp.lang.c
- Subject: Re: Explain this> %s \"%[^\"]\"
- Date: Thu, 29 Feb 1996 17:07:13 +0200
- Organization: Carelcomp Forest
- Message-ID: <3135C121.5E6B@cmt.lpr.mail.carel.fi>
- References: <4h2t6u$v56@useneta1.news.prodigy.com>
- NNTP-Posting-Host: renoir.cclahti.carel.fi
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (WinNT; I)
-
- David Cunningham wrote:
- >
- > I have a file that contains text like this:
- >
- > 012345678 "Joe Smith"
- >
- > I also have an example of sscanf to pick out these fields. Can someone
- > translate what \"%[^\"]\"%d" means. I need to have a good understanding
- > of this for a homework assignment. It looks like this:
- >
- > sscanf(buff,"%s \ "%[^\"]\" %d",student_list->ss_num,student_list->name);
- >
- > Please explain what these hieroglyphics mean, character by character.
- >
- > The sscanf will produce this--> 012345678 Joe Smith
- >
-
- What you wrote in the sscanf statement above, produces a syntax error and will not
- compile. You probably meant this format string:
-
- "%s \"%[^\"]\"%d"
-
- Anyway, inside a format string the escape sequence \" means that the string contains a
- quotation mark (it doesn't here mark the end of the string). The construct %[^\"] means
- that the string is read until the first character that appears in the character set (ie.
- a quotation mark here). If it read %[\"], the string would be read until the first
- character that does _not_ appear in the character set. I'll pass the remark that your
- program will not run correctly, if you write the sscanf function call this way. Anyway,
- you may find better approach. Skim through the online helps for 'Format Specification
- Fields' or take a look at a good book. That should help you through your homework
- assignment. :)
-
-
- Later,
- AriL
- --
- All my opinions are mine and mine alone.
-